package cn.gjxblog.mq.mechanism.qos;

import cn.gjxblog.mq.utils.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;


/**
 * @author gjx
 * @version v1.0
 * @Description
 * @date 2019/7/4 11:48
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        Connection connection = ConnectionUtils.getConnection();

        //3 通过connection创建channel
        Channel channel = connection.createChannel();

        //44指定我们的消息模式 消息的确认模式
        channel.confirmSelect();

        //5 通过channel发送数据
        String exchangeName = "test_qos_exchange";
        String routingKey = "qos.save";
        String msg = "Hello RabbitMQ!";

        for (int i = 0; i < 5; i++) {
            channel.basicPublish(exchangeName,routingKey,null,msg.getBytes());
        }

        //关闭相关连接
        channel.close();
        connection.close();
    }
}
